// pages/comment/comment.js
import {
  request,
} from '../../utils/util.js'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    tab_index: 0,
    commentList: [],
    has_more: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getCommnetList();
  },

  //tap切换事件
  changeTap: function(e) {
    let index = e.currentTarget.dataset.index;
    this.setData({
      tab_index: index
    })
    this.data.page = 1;
    this.data.commentList = [];
    this.getCommnetList();
  },

  //获取评论列表
  getCommnetList: function() {
    let data = {
      page: this.data.page,
      nav_type: (this.data.tab_index + 1)
    }

    request({
      url: 'Comment/commentUser',
      data: data,
      method: 'POST',
      success: data => {
        let has_more = true;
        if (data.list.length < 10) {
          has_more = false;
        }
        this.setData({
          commentList: [...this.data.commentList, ...data.list],
          has_more
        })
      },
    })
  },

  getMore: function() {
    this.data.page++;
    this.getCommnetList();
  }
})